package codec;

import org.apache.mina.core.buffer.IoBuffer;
import org.apache.mina.core.session.IoSession;
import org.apache.mina.filter.codec.CumulativeProtocolDecoder;
import org.apache.mina.filter.codec.ProtocolDecoderOutput;

/**
 * Created by ryan on 15-8-25.
 */
public class FileRequestDecoder extends CumulativeProtocolDecoder {

    protected boolean doDecode(IoSession ioSession, IoBuffer in, ProtocolDecoderOutput out) throws Exception {
        if(in.remaining() >=8 ) {
            long startPos = in.getLong();
            FileRequest fr = new FileRequest(startPos);
            out.write(fr);
            return true;
        }
        return false;

    }
}
